package com.learn.xueer.ui.fragment

import android.os.Bundle
import androidx.lifecycle.Observer
import androidx.navigation.fragment.findNavController
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.bitmap.CircleCrop
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
import com.bumptech.glide.request.RequestOptions
import com.learn.xueer.R
import com.learn.xueer.app.base.BaseFragment1
import com.learn.xueer.app.util.CacheUtil
import com.learn.xueer.databinding.FragmentWordPkSearchBinding
import com.learn.xueer.ui.viewmodel.PkSearchViewModel
import kotlinx.android.synthetic.main.fragment_word_pk_search.iv_avatar

class PkSearchFragment : BaseFragment1<PkSearchViewModel, FragmentWordPkSearchBinding>() {
    override fun initView(savedInstanceState: Bundle?) {
        CacheUtil.getUser()?.let {
            Glide.with(iv_avatar)
                .load(it.avatar)
                .apply(RequestOptions.bitmapTransform(CircleCrop()))
                .transition(DrawableTransitionOptions.withCrossFade(500))
                .into(iv_avatar)
        }
        mViewModel.requestComplete.observe(this, Observer {
            if (it) {
                val bundle = Bundle()
                bundle.putSerializable("pkInfo", mViewModel.pkInfo)
                findNavController().navigate(R.id.navToWait, bundle)
            }
        })
        mViewModel.getPkInfo()
        dismissLoading()
    }
}